//
// Created by Liming Shao on 11/7/2017.
//

#include <cstdlib>
#include "C095.h"
#include <iostream>
using namespace std;

Node *getLeft(Node* head){
    if (head->left != nullptr)
        return head->left;
    else
        return head->right;
}

Node *getRight(Node* head){
    if (head->right != nullptr)
        return head->right;
    else
        return head->left;
}

/*
1. 查询最左和最右节点。
2. 顺序打印最左节点。
3. 遍历二叉树，打印非最左最右的叶子节点。
4. 倒序打印最右节点。
*/
void C095::printEdge1(Node *head) {
    if (head == nullptr) return;

    int height = getHeight(head, 0);




}

void C095::printEdge2(Node *head) {

}

void C095::test() {
    /*
     *  使用如下二叉树
     *                1
     *     2                     3
     *       4                5     6
     *     7   8            9   10
     *           11      12
     *         13  14  15   16

     */

    Node *head = newNode(1);
    head->left = newNode(2);
    head->right = newNode(3);
    head->left->right = newNode(4);
    head->right->left = newNode(5);
    head->right->right = newNode(6);

    head->left->right->left = newNode(7);
    head->left->right->right = newNode(8);

    head->right->left->left = newNode(9);
    head->right->left->right = newNode(10);

    head->left->right->right->right = newNode(11);
    head->right->left->left->left = newNode(12);

    head->left->right->right->right->left = newNode(13);
    head->left->right->right->right->right = newNode(14);
    head->right->left->left->left->left = newNode(15);
    head->right->left->left->left->right = newNode(16);

    cout << getHeight(head, 0);
}

Node *C095::newNode(int val) {
    auto ret = (Node*)malloc(sizeof(Node));
    ret->value = val;
    ret->left = nullptr;
    ret->right = nullptr;
    return ret;
}

int C095::getHeight(Node *head, int l) {
    if (head == nullptr)
        return l;

    int lf = getHeight(head->left, l+1);
    int lr = getHeight(head->right, l+1);
    return (lf>lr?lf:lr);
}



